<template>
  <view class="realBox">
    <view class="contentBox">
      <u-form :model="form" ref="uForm">
        <u-form-item label-width="140" label="姓名" prop="name">
          <u-input v-model="form.name" />
        </u-form-item>
        <u-form-item label-width="140" label="手机号" prop="phone">
          <u-input v-model="form.phone" maxlength="11" />
        </u-form-item>
        <u-form-item label-width="140" label="身份证号" prop="card">
          <u-input v-model="form.card" maxlength="18" />
        </u-form-item>
      </u-form>
      <view class="tip">
        请填写真实的姓名和身份证号，如果因为填写的身份证号信息有误，导致提现不到账，后果自负。
      </view>
    </view>
    <view class="btn" @click="setcard()">
      确认
    </view>
  </view>
</template>

<script>
  import {
    mapMutations,
    mapActions,
    mapState
  } from 'vuex';
  import FormValidate from '@/shopro/validate/form';
  export default {
    components: {},
    computed: {
      ...mapState({
        userInfo: ({
          user
        }) => user.userInfo,
        authType: ({
          user
        }) => user.authType
      })
    },
    data() {
      return {
        card: {
          id: '' //this.userInfo.id
        },
        form: {
          name: '',
          phone: '',
          card: ''
        },
        rules: {
          name: FormValidate.realName,
          phone: FormValidate.mobile,
          card: FormValidate.idcard,
        }
      }
    },
    onReady() {
      this.$refs.uForm.setRules(this.rules);
    },
    methods: {
      setcard() {
        let that = this;
        console.log(that.userInfo.id)
        that.$refs.uForm.validate(valid => {
          if (valid) {
            that.$http('user.card', {
              id: that.userInfo.id,
              real_name: that.form.name,
              mobile: that.form.phone,
              idcard: that.form.card
            }).then(res => {
              if (res.code === 1) {
                uni.showToast({
                  title: '认证成功',
                  icon: 'none',
                  success() {
                    setTimeout(function() {
                      uni.redirectTo({                        
                        url: '/pages/user/address/edit?type=0'
                      })
                    }, 500)
                  }
                })
              } else {
                uni.showToast({
                  title: res.msg,
                  icon: 'none'
                })
              }

            })
          }
        });

      }
    }
  }
</script>

<style lang="scss" scoped>
  .realBox {
    .contentBox {
      width: 720rpx;
      height: 845rpx;
      padding: 20rpx;
      background: #FFFFFF;
      box-shadow: 0px 1px 20px 0px rgba(0, 0, 0, 0.05);
      border-radius: 12px;
      margin: 30rpx 15rpx;

      .tip {
        width: 649rpx;
        height: 61rpx;
        font-size: 22rpx;
        font-weight: 500;
        color: #FF8742;
      }
    }

    .btn {
      width: 333rpx;
      height: 67rpx;
      line-height: 67rpx;
      text-align: center;
      background: #FFAC5A;
      border-radius: 34rpx;
      margin: 60rpx auto;
      color: #FFFFFF;
    }
  }
</style>
